/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.knife.blog.service;

import com.knife.web.tools.EasyDBODAO;
import com.knife.web.tools.IDAO;
import com.knife.blog.domain.BlogInfo;
import com.knife.blog.domain.BlogTemplate;
import com.knife.blog.util.BlogFileUtil;

import java.util.Date;
import java.util.TimerTask;

/**
 *
 * @author Administrator
 */
public class PublishTask extends TimerTask {

    private static IDAO dao = EasyDBODAO.getInstance();
    private boolean isRunning = false;
    private HTMLGenerater generater=new HTMLGenerater();
    private static long autoRetryTime = 1000 * 60 * 1;
    private String siteroot = com.knife.blog.service.Config.getWwwpath();

    @Override
    public void run() {
        if (!isRunning) {
            System.out.println("KnifeBlog:start to generate html.");
            siteroot=generater.getBasePath();
            generate();
        }
    }

    public void generate() {
        isRunning = true;
        System.out.println("自动生成HTML的线程已启动！");
            try {
            	System.out.println(new Date());
                generater.saveToHTML();
                generater.saveIndexArticleToHTML();
                generater.saveIndexCircleToHTML();
                generater.saveIndexPhotoToHTML();
                isRunning = false;
            } catch (Exception e) {
                e.printStackTrace();
            }
            isRunning = false;
    }
}
